package com.duobaoyu.dby.supply.admin.controller.config;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.admin.converter.SupplyChainAdminConverter;
import com.duobaoyu.dby.supply.biz.service.config.SystemLogService;
import com.duobaoyu.dby.supply.common.biz.dto.config.SystemLogDTO;
import com.duobaoyu.dby.supply.common.biz.vo.config.SystemLogVO;
import com.duobaoyu.dby.supply.db.entity.message.SystemLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;


/**
 * 系统操作日志
 *
 * @auther tianxiaoqiang
 * @describe 系统操作日志表前端控制器
 * @since 2022-06-22 10:45:14
 */
@RestController
@RequestMapping("/admin/system-log")
@RequiredArgsConstructor
@Api(value = "system-log", tags = "系统操作日志表")
public class SystemLogController {

	private final SystemLogService systemLogService;
	private final SupplyChainAdminConverter supplyChainAdminConverter;

	/**
	 * 查询系统操作日志信息详情
	 *
	 * @param id
	 * @return
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "查询系统操作日志信息详情", notes = "根据id查询系统操作日志信息详情")
	@SupplySysLog(value = "查询系统操作日志信息详情",operationType = OperationTypeEnum.SELECT)
	public R<SystemLogVO> getOne(@NotNull(message = "系统操作日志ID不能为空") @PathVariable("id") String id) {

		return R.ok(supplyChainAdminConverter.toSystemLog(systemLogService.getById(id)));
	}

	/**
	 * 查询系统操作日志
	 *
	 * @param systemLog
	 * @return
	 */
	@PostMapping("/page")
	@ApiOperation(value = "查询系统操作日志信息", notes = "查询系统操作日志信息")
	@SupplySysLog(value = "查询系统操作日志",operationType = OperationTypeEnum.SELECT)
	public R<Page<SystemLogVO>> queryOne(@RequestBody SystemLogDTO systemLog) {
		Page<SystemLog> page = systemLogService.page(systemLog);
		return R.ok(supplyChainAdminConverter.toSystemLogPage(page));
	}
}

